package com.hejia.alauda.entity;

import java.util.Date;

import javax.persistence.Column;

import com.hejia.alauda.utils.DataSecurity;



/**
 * 绑定银行卡 Created by Johnny(johnny@hejiajinrong.com) on 14-9-10.
 */
public class BankCard extends BaseEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1613659755725227750L;
	
	//BINDED-已经认证绑定,UNBIND-未绑定
	public enum Status{
		BINDED,UNBIND
	}

	// CARD-卡, BOOK-存折
	public enum CardType {
		CARD, BOOK
	}

	// ID_CARD-身份证，PASSPORT-护照，OTHER-其他
	public enum CertType {
		ID_CARD, PASSPORT, OTHER
	}

	@Column
	private String bankName;// 银行名称
	

	@Column(length = 10)
	private String bankCode;// 银行编码

	@Column(length = 4)
	private String openBankId;// 开户行号

	@Column
	private String cardNumber;// 卡号

	@Column(length = 100)
	private String userName;// 持卡人姓名

	@Column(length = 10)
	private CardType cardType;// 卡折标志

	@Column(length = 2)
	private CertType certType;// 证件类型

	@Column(length = 25)
	private String certId;// 证件号

	@Column(length = 40)
	private String mobile;// 手机号码
	
	
	@Column
	private Date lastTime;//最近使用时间
	
	@Column(length = 16)
	private String llpayAgreeNo;//连连支付签约协议编号

	@Column(length = 64)
	private String umpayAgreeNo;// 联动优势支付签约协议号
	
	private String maxPayInfo;//支付限额信息
	

	@Column(length=20)
	private Status status;
	
	private Boolean useable;//是否可用

	@Column
	private User user;

	public String getBankName() {
		return bankName;
	}

	public void setBankName(String bankName) {
		this.bankName = bankName;
	}

	public String getCardNumber() {
		return cardNumber;
	}

	public void setCardNumber(String cardNumber) {
		this.cardNumber = cardNumber;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String getOpenBankId() {
		return openBankId;
	}

	public void setOpenBankId(String openBankId) {
		this.openBankId = openBankId;
	}

	public CardType getCardType() {
		return cardType;
	}

	public void setCardType(CardType cardType) {
		this.cardType = cardType;
	}

	public String getUserName() {
		if (userName != null) {
			return userName.trim();
		}
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public CertType getCertType() {
		return certType;
	}

	public void setCertType(CertType certType) {
		this.certType = certType;
	}

	/**
	 * 获取卡折标志代码
	 * 
	 * @return
	 */
	public String getCardTypeCode() {
		String code = "06";
		if (getCardType() == null) {
			return code;
		}
		switch (getCardType()) {
		case CARD:
			code = "0";
			break;
		case BOOK:
			code = "1";
			break;

		default:
			break;
		}
		return code;
	}

	public static CardType getCardType(String code) {
		if ("0".equals(code)) {
			return CardType.CARD;
		} else if ("1".equals(code)) {
			return CardType.BOOK;
		}
		return null;
	}

	public String getCertId() {
		return certId;
	}

	public void setCertId(String certId) {
		this.certId = certId;
	}

	/**
	 * 获取证件类型代码
	 * 
	 * @return
	 */

	public String getCertTypeCode() {
		String code = "06";
		if (getCertType() == null) {
			return code;
		}
		switch (getCertType()) {
		case ID_CARD:
			code = "01";
			break;
		case PASSPORT:
			code = "03";
			break;

		default:
			break;
		}
		return code;
	}

	public static CertType getCertType(String code) {
		if ("01".equals(code)) {
			return CertType.ID_CARD;
		} else if ("03".equals(code)) {
			return CertType.PASSPORT;
		}
		return CertType.OTHER;
	}

	/**
	 * 获取证件类型值
	 * 
	 * @return
	 */

	public String getCertTypeValue() {
		String value = "其他";
		if (getCertType() == null) {
			return value;
		}
		switch (getCertType()) {
		case ID_CARD:
			value = "身份证";
			break;
		case PASSPORT:
			value = "护照";
			break;

		default:
			break;
		}
		return value;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public Status getStatus() {
		return status;
	}
	
	/**
	 * 获取状态名称
	 * @return	状态名称
	 */
	public String getStatusName() {
		
		if(this.status == null){
			return "";
		}
		
		String name = "";
		switch(this.status){
		case BINDED:
			name = "已绑定";
			break;
		case UNBIND:
			name = "未绑定";
			break;
		}
		
		return name;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	public String getBankCode() {
		return bankCode;
	}

	public void setBankCode(String bankCode) {
		this.bankCode = bankCode;
	}

	public Date getLastTime() {
		return lastTime;
	}

	public void setLastTime(Date lastTime) {
		this.lastTime = lastTime;
	}

	public String getMaxPayInfo() {
		return maxPayInfo;
	}

	public void setMaxPayInfo(String maxPayInfo) {
		this.maxPayInfo = maxPayInfo;
	}

	public String getLlpayAgreeNo() {
		return llpayAgreeNo;
	}

	public void setLlpayAgreeNo(String llpayAgreeNo) {
		this.llpayAgreeNo = llpayAgreeNo;
	}

	public String getUmpayAgreeNo() {
		return umpayAgreeNo;
	}

	public void setUmpayAgreeNo(String umpayAgreeNo) {
		this.umpayAgreeNo = umpayAgreeNo;
	}

	public Boolean getUseable() {
		return useable;
	}

	public void setUseable(Boolean useable) {
		this.useable = useable;
	}
	
	/**
	 * 获取隐蔽的公民身份号码
	 * @return 隐蔽的公民身份号码
	 */
	public String getMaskedCertId(){
		return DataSecurity.maskIdCard(this.certId);
	}
	
	/**
	 * 获取隐蔽的持卡人姓名
	 * @return 隐蔽的持卡人姓名
	 */
	public String getMaskedUserName(){
		return DataSecurity.maskPersonName(this.userName);
	}
	
	/**
	 * 获取隐蔽的银行卡号
	 * @return	隐蔽的银行卡号
	 */
	public String getMaskedCardNumber(){
		return DataSecurity.maskBankCardNumber(this.cardNumber);
	}
	
	//银行卡尾号
	public String getLastDigitsOfCardNumber(){
		return (cardNumber!=null && cardNumber.length()>4)?cardNumber.substring(cardNumber.length()-4, cardNumber.length()):"";
	} 
}
